import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'pages/home_page.dart';
import 'pages/news_detail_page.dart';
import 'pages/todos_page.dart';
import 'pages/settings_page.dart';
import 'providers/settings_provider.dart';

/// 综合实战App
/// 整合: Riverpod + go_router + Dio + rxDart
class ComprehensiveApp extends ConsumerWidget {
  const ComprehensiveApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // 监听主题模式
    final themeMode = ref.watch(themeModeProvider);

    return MaterialApp.router(
      title: '综合实战 App',
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true),
      darkTheme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple, brightness: Brightness.dark),
        useMaterial3: true,
      ),
      themeMode: themeMode,
      routerConfig: _router,
      debugShowCheckedModeBanner: false,
    );
  }
}

// go_router配置
final _router = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(path: '/', name: 'home', builder: (context, state) => const ComprehensiveHomePage()),
    GoRoute(
      path: '/news/:id',
      name: 'news-detail',
      builder: (context, state) {
        final id = state.pathParameters['id']!;
        return NewsDetailPage(newsId: id);
      },
    ),
    GoRoute(path: '/todos', name: 'todos', builder: (context, state) => const TodosPage()),
    GoRoute(path: '/settings', name: 'settings', builder: (context, state) => const SettingsPage()),
  ],
);
